﻿@model MatchPlayResult

@{
    ViewBag.Title = "Matchplay";
}

<div class="page-header">
    <h1><span class="glyphicon glyphicon-tower"></span> @ViewBag.Title</h1>
</div>

<div class="row">
    <div class="col-md-4">
        <h2>Indberet resultat</h2>
        <hr />

        @if (!ViewData.ModelState.IsValid)
        {
            <div class="alert alert-danger alert-dismissable">
                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                @Html.ValidationSummary("", new { @style = "color: #fff;" })
            </div>
        }

        @using (Html.BeginForm("Create", "MatchPlay", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { role = "form", @class = "form-horizontal" }))
        {
            @Html.AntiForgeryToken()

            @*<div class="form-group">
                    <label for="date" class="col-sm-2 control-label">dato</label>
                    <div class="col-sm-6">
                        <div class="input-group">
                            <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
                            <input id="Date" name="Date" class="form-control datepicker" value="@Model.Date.ToShortDateString()">
                        </div>
                    </div>
                </div>*@

            <div class="form-group">
                @Html.LabelFor(m => m.Date, new { @class = "col-sm-2 control-label" })
                <div class="col-sm-10">
                    @*@Html.EditorFor(x => x.Date, new { maxDate = DateTime.Today })*@
                    <div class="input-group">
                        <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
                        <input type="text" id="Date" name="Date" class="form-control datepicker">
                    </div>
                </div>
            </div>

            <div class="form-group">
                <label for="opponent" class="col-sm-2 control-label">spillet imod</label>
                <div class="col-sm-10">
                    <div class="input-group">
                        <span class="input-group-addon"><span class="glyphicon glyphicon-user"></span></span>
                        @Html.DropDownListFor(m => m.Player2Id, new SelectList(ViewBag.Players, "Id", "DisplayName"), new { @class = "form-control" })
                    </div>
                </div>
            </div>

            <div class="form-group">
                <label for="winner" class="col-sm-2 control-label">resultat</label>
                <div class="col-sm-10">
                    <div class="input-group">
                        <span class="input-group-addon"><span class="glyphicon glyphicon-tower"></span></span>
                        <select id="ResultString" name="ResultString" class="form-control" required></select>
                    </div>
                </div>
            </div>

            <div class="form-group">
                <label for="submit" class="col-sm-2 control-label"></label>
                <div class="col-sm-9">
                    <button type="submit" class="btn btn-default">opret</button>
                </div>
            </div>
        }
    </div>

    <div class="col-md-8">
        <h2>Dine spillede matcher</h2>
        @{ Html.RenderAction("AllMatchesForPlayer", "Matchplay", new { PlayerId = ViewBag.CurrentPlayerId }); }
    </div>
</div>

@section Scripts {
    @Scripts.Render("~/bundles/globalize")
    @Scripts.Render("~/bundles/jqueryval")
    @Scripts.Render("~/Scripts/_thecup_editing.js")

    <script type="text/javascript">
        var playerid = parseInt("@ViewBag.CurrentPlayerId");

        $(document).ready(function () {

            // http://eternicode.github.io/bootstrap-datepicker/?markup=input&format=dd-mm-yyyy&weekStart=1&startDate=&endDate=&startView=0&minViewMode=0&todayBtn=false&language=da&orientation=auto&multidate=&multidateSeparator=&calendarWeeks=on&autoclose=on&todayHighlight=on&keyboardNavigation=on&forceParse=on#sandbox
            // TODO: only attach event, we're setting datepickers elsewhere
            $('#Date').on('dp.change', function (ev) {
                matchplay.updateOpponents(this, ev, playerid);
            });

            $('#Player2Id').on('change', function (e) {
                matchplay.updatePossibleWinners(playerid);
            });

            // initialize dropdown with first element from opponents
            matchplay.updatePossibleWinners(playerid);
        });


    </script>
}

